#include <bits/stdc++.h>
using namespace std;
int t, a[200005], b[200005], ans;
bool g[200005];
int main()
{

    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    for(int i = 1; i <= t; i++)
    {
        int n;
        cin >> n;
        for(int j = 1; j <= n; j++)
        {
            cin >> a[j];
        }
        int se = 0;
        g[n] = se;
        for(int j = n; j > 1; j--)
        {
            for(int k = j - 1; k >= 1; k--)
            {
                if(a[k] == a[j])
                {
                    g[k] = g[j];
                    se = (se + 1) % 2;
                    for(int l = k + 1; l < j; l++)
                    {
                        g[l] = se;
                    }
                }
            }
        }
        ans = 0;
        for(int j = 1; j <= n; j++) cout << g[j] << " ";
        cout << "\n";
        for(int j = n; j > 1; j--)
        {
            for(int k = j - 1; k >= 1; k--)
            {
                if(g[k] == g[j])
                {
                    if(a[k] == a[j]) ans += a[k];
                    break;
                }
            }
        }
        cout << ans << "\n";
    }
    return 0;
}
